from PyQt5.QtWidgets import QWidget, QMessageBox
from res.ui import chginfo
from src.util.entity import 班主任
from src.util.mydb2 import mysession


class chginfowgt(QWidget):
    def __init__(self, parent):
        super().__init__()
        ui = chginfo.Ui_Form()
        ui.setupUi(self)
        self.ui = ui
        self.parent_ = parent

        tinfo:班主任 = parent.tinfo
        ui.pushButton.clicked.connect(self.chg)
        ui.lineEdit_1.setText(tinfo.教师号)  # type: ignore
        ui.lineEdit_2.setText(tinfo.姓名)  # type: ignore
        ui.lineEdit_3.setText(tinfo.性别)  # type: ignore
        ui.lineEdit_4.setText(tinfo.班级id)  # type: ignore

    def chg(self):
        tinfo:班主任 = self.parent_.tinfo
        # print("\n\n" + ui.lineEdit_3 + "\n\n")
        tinfo.教师号 = self.ui.lineEdit_1.text()  # type: ignore
        tinfo.姓名 = self.ui.lineEdit_2.text()  # type: ignore
        tinfo.性别 = self.ui.lineEdit_3.text()  # type: ignore
        tinfo.班级id = self.ui.lineEdit_4.text()  # type: ignore
        self.parent_.tno = tinfo.教师号
        mysession.commit()
        QMessageBox.information(self, "提示", "修改成功")
        self.hide()
